﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AutoOiSystem
{
    /// <summary>
    /// ConnectWindow.xaml 的互動邏輯
    /// </summary>
    public partial class ConnectWindow : Window
    {
        public ConnectWindow()
        {
            InitializeComponent();
            ScanTxt.Text = "OI服务器连接中......";
            CheckConnect();
        }

        public void CheckConnect()
        {
            Ping ping=new Ping();
            ping.PingCompleted += Ping_PingCompleted;
            ping.SendAsync("10.198.240.103", null);
           
        }

        private void Ping_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            var reply = e.Reply;

            if (reply.Status == IPStatus.Success)
            {
                ScanTxt.Text = "OI服务器连接成功";
                MainWindow mw = new MainWindow();
                mw.Show();

                Close();
            }
            else
            {
                ScanTxt.FontSize = 30;
                ScanTxt.Text = "OI服务器连接异常,程序3S后退出";
                ScanTxt.Foreground = Brushes.Red;

                Thread th = new Thread(new ThreadStart(ConnectThread));
                th.Start();
               
            }

        }


        void ConnectThread()
        {
            Thread.Sleep(3000);
            Environment.Exit(0);
        }
    }




  
}
